package basic.basic_class07;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 手撕基础班7
 */
public class Test {

    // 会议室安排问题
    public static class Project{
        Integer start;
        Integer end;

        public Project(int start, int end){
            this.start = start;
            this.end = end;
        }
    }

    // start表示项目的开始时间
    public static int bestArrange(Project[] programs, int start) {
        // 首先将项目按照结束时间进行排序
        Arrays.sort(programs, new Comparator<Project>() {
            @Override
            public int compare(Project o1, Project o2) {
                return o1.end - o2.end;
            }
        });
        // 开始遍历项目列表
        int res = 0;
        for (int i = 0; i < programs.length; i++) {
            if(programs[i].start >= start){
                res++;
                start = programs[i].end;
            }
        }
        return res;
    }


    public static void main(String[] args) {
        Project p1 = new Project(1,3);
        Project p2 = new Project(2,4);
        Project p3 = new Project(3,6);
        Project p4 = new Project(5,6);
        Project p5 = new Project(7,8);
        Project[] ps = new Project[]{p1,p2,p3,p4,p5};
        int count = bestArrange(ps, 1);
        System.out.println(count);
    }

}
